/**
 * Course			:	ISYS2119 - BIS Development 2
 * Assignment		:	02
 * Date due			:	01/08/2012
 * Program 			:	Saigon Bike Rental Catalogue System
 * 
 * Programmer		:	Vuu Ngoc My Linh, Tran Thi Van Anh
 * StudentID     	:	s3342015, s3342025
 * Attributions		:	Lecture slides, Blackboard, Tutorials, Websites
 * 
 * Setter list		: 	public void setBikeId(int bikeId)
 * 						public void setModelName(String modelName)
 * 						public void setYear(int year)
 * 						public void setDescription(String description)
 * 						public void setEngineCapacity(String modelName)
 * 						public void setMonthlyRent(int year, int EngineCapacity, String modelName)
 * 						public void setSpecifications(String specifications)
 * 
 * Getter list		:	public int getBikeId();
 * 						public String getModelName()
 * 						public int getYear()
 * 						public String getDescription()
 * 						public int getEngineCapacity() 
 * 						public double getMonthlyRent()
 * 						public String getSpecifications()
 * 
 * Constructor list	:	public Bike()
 * 						public Bike(int bikeId, String modelName)
 * 						public Bike(int bikeId, String modelName, int year, String description, int engineCapacity, double rentalCost, String specifications)
 * 						
 * Function list	:	public double calcMonthlyRent(int year, int EngineCapacity, String modelName) 
 * 						public int determineEngineCapacity(String modelName)
 * 
 */

package rmit.ISYS2119.assign02;

import java.util.ArrayList;
import java.util.Calendar;

public class Bike {

	// Declare Variables
	private int bikeId;
	private String modelName;
	private int year;
	private String description;
	private int engineCapacity;
	private double rentalCost;
	// private String Specifications;
	private ArrayList<BikeEngineSpecification> specifications;

	// Methods

	/**
	 * @return the bikeId
	 */
	public int getBikeId() {
		return bikeId;
	}

	/**
	 * @param bikeId
	 *            the bikeId to set
	 */
	public void setBikeId(int bikeId) {
		this.bikeId = bikeId;

	}

	/**
	 * @return the modelName
	 */
	public String getModelName() {
		return modelName;
	}

	/**
	 * @param modelName
	 *            the modelName to set
	 */
	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	/**
	 * @return the year
	 */
	public int getYear() {
		return year;
	}

	/**
	 * @param year
	 *            the year to set
	 */
	public void setYear(int year) {
		this.year = year;
	}

	/**
	 * @return the description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * @param description
	 *            the description to set
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * @return the EngineCapacity
	 */
	public int getEngineCapacity() {
		return engineCapacity;
	}

	/**
	 * @param engineCapacity
	 *            the engineCapacity to set
	 */
	public void setEngineCapacity(String modelName) {
		this.engineCapacity = determineEngineCapacity(modelName);
	}

	/**
	 * determine the engine capacity
	 */
	public int determineEngineCapacity(String modelName) {

		// Determine Engine Capacity
		switch (modelName) {
		case "Honda Wave Rs":
			engineCapacity = 100;
			break;
		case "Honda Air Blade":
			engineCapacity = 100;
			break;
		case "SYM Attila":
			engineCapacity = 125;
			break;
		case "SYM Victoria":
			engineCapacity = 125;
			break;
		case "SYM Magic":
			engineCapacity = 125;
			break;
		case "Yamaha Nouvo":
			engineCapacity = 115;
			break;
		case "Yamaha Mio":
			engineCapacity = 115;
			break;
		case "Yamaha Mio Classico":
			engineCapacity = 115;
			break;
		case "Yamaha Majestic":
			engineCapacity = 125;
			break;
		}
		return engineCapacity;

	}

	/**
	 * @return the specifications
	 */
	public ArrayList<BikeEngineSpecification> getSpecifications() {
		return specifications;
	}

	/**
	 * @param specifications
	 *            the specifications to set
	 */
	public void setSpecifications(
			ArrayList<BikeEngineSpecification> specifications) {
		this.specifications = specifications;
	}

	public void addSpecifications(BikeEngineSpecification newSpec) {
		specifications.add(newSpec);
	}

	public void removeSpecifications() {
		specifications.clear();
	}

	/**
	 * @return the monthlyRent
	 */
	public double getRentalCost() {
		return rentalCost;
	}

	/**
	 * @param monthlyRent
	 *            the monthlyRent to set
	 */
	public void setRentalCost(int year, int EngineCapacity, String modelName) {
		this.rentalCost = Math.round(calcMonthlyRent(year, EngineCapacity,
				modelName));
	}

	/**
	 * calculate Monthly Rent
	 */
	public double calcMonthlyRent(int year, int EngineCapacity, String modelName) {

		// Declare Variables
		double appreciationRate = 0;
		double baseCost = 0;
		double appreciationCost = 0;
		double depreciationCost = 0;
		double totalRent = 0;

		// Determine Base Rental Price
		switch (EngineCapacity) {
		case 100:
			baseCost = 1000000;
			break;
		case 115:
			baseCost = 1300000;
			break;
		case 125:
			baseCost = 1500000;
			break;
		}

		// Determine Appreciation Rate
		switch (modelName) {
		case "Honda Wave Rs":
			appreciationRate = 0.04;
			break;
		case "Honda Air Blade":
			appreciationRate = 0.06;
			break;
		case "SYM Attila":
			appreciationRate = 0.01;
			break;
		case "SYM Victoria":
			appreciationRate = 0.02;
			break;
		case "SYM Magic":
			appreciationRate = 0.03;
			break;
		case "Yamaha Nouvo":
			appreciationRate = 0.02;
			break;
		case "Yamaha Mio":
			appreciationRate = 0.04;
			break;
		case "Yamaha Mio Classico":
			appreciationRate = 0.06;
			break;
		case "Yamaha Majestic":
			appreciationRate = 0.06;
			break;
		}

		// Define Appreciation Cost
		appreciationCost = baseCost * appreciationRate;

		// Get Calendar
		Calendar calendar = Calendar.getInstance();

		// Get current year
		int currentYear = calendar.get(Calendar.YEAR);

		// Define Depreciation Cost
		depreciationCost = baseCost
				* (((double) currentYear - (double) year) / ((double) 2 * 100));
		totalRent = baseCost + appreciationCost - depreciationCost;

		return totalRent;

	}

	/**
	 * 
	 */
	public Bike() {
		setBikeId(0000);
		setModelName("");
		setYear(0);
		setDescription("");
		setEngineCapacity("");
		setRentalCost(0, 0, "");
		specifications = new ArrayList<BikeEngineSpecification>();
	}

	/**
	 * @param bikeId
	 * @param modelName
	 * @param year
	 * @param description
	 */
	public Bike(int bikeId, String modelName) {
		setBikeId(bikeId);
		setModelName(modelName);
		setYear(0);
		setDescription("");
		setEngineCapacity("");
		setRentalCost(0, 0, "");
		specifications = new ArrayList<BikeEngineSpecification>();
	}

	/**
	 * @param bikeId
	 * @param modelName
	 * @param year
	 * @param description
	 * @param engineCapacity
	 * @param rentalCost
	 * @param specifications
	 */
	public Bike(int bikeId, String modelName, int year, String description,
			int engineCapacity, double rentalCost,
			BikeEngineSpecification specifications) {
		setBikeId(bikeId);
		setModelName(modelName);
		setYear(year);
		setDescription(description);
		setEngineCapacity(modelName);
		setRentalCost(year, engineCapacity, modelName);
		addSpecifications(specifications);
	}

}